package com.cqrt.controller;

import com.cqrt.entity.AuthorityManagementDO;
import com.cqrt.service.AuthorityManagementService;
import com.github.pagehelper.PageInfo;
import com.ty.basic.entity.org.UserDO;
import com.ty.basic.response.ResponseResult;
import com.ty.ppm.model.constant.ApiPathConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Author：lotus
 * @DATE: 2025/7/16 21:54
 */

@RestController
@Api(tags = "权限管控")
@RequestMapping(ApiPathConstant.PARENT_VERSION_ONE_PATH + "authority")
public class RTAuthorityManagementController {


    @Autowired
    private AuthorityManagementService authorityManagementService;

    @PostMapping("/insertAuthority")
    @ApiOperation(value = "新增", produces = "application/json; charset=utf-8")
    public ResponseResult<T> insertAuthority(@RequestBody AuthorityManagementDO authorityManagementDO) {
        authorityManagementService.insertAuthority(authorityManagementDO);
        return ResponseResult.success();

    }

    @PostMapping("/updateAuthority")
    @ApiOperation(value = "修改", produces = "application/json; charset=utf-8")
    public ResponseResult<T> updateAuthority(@RequestBody AuthorityManagementDO authorityManagementDO) {

        authorityManagementService.updateAuthority(authorityManagementDO);
        return ResponseResult.success();
    }

    @GetMapping("/selectAllAuthority")
    @ApiOperation(value = "查询所有", produces = "application/json; charset=utf-8")
    public ResponseResult<PageInfo<AuthorityManagementDO>> selectAllAuthority(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "20") int pageSize) {

        return ResponseResult.success(authorityManagementService.selectAllAuthority(pageNum, pageSize));
    }

    @DeleteMapping("/deleteAuthority")
    @ApiOperation(value = "删除", produces = "application/json; charset=utf-8")
    public ResponseResult<T> deleteAuthority(BigInteger oid) {

        authorityManagementService.deleteAuthorityByOid(oid);
        return ResponseResult.success();
    }

    @GetMapping("/selectAuthorityByOid")
    @ApiOperation(value = "根据用户oid查询", produces = "application/json; charset=utf-8")
    public ResponseResult<List<AuthorityManagementDO>> selectAuthorityByUid(BigInteger oid) {
        return ResponseResult.success(authorityManagementService.selectAuthorityByUid(oid));
    }

    @GetMapping("/selectAuthorityUser")
    @ApiOperation(value = "查询用户信息", produces = "application/json; charset=utf-8")
    public ResponseResult<PageInfo<UserDO>> selectAuthorityUser(
            @RequestParam(required = false) String userName,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int pageSize) {
        PageInfo<UserDO> userDOPageInfo=authorityManagementService.selectAuthorityUser(userName,page,pageSize);
        return ResponseResult.success(userDOPageInfo);
    }

    @GetMapping("/selectAuthorityProjectType")
    @ApiOperation(value = "查询项目类型", produces = "application/json; charset=utf-8")
    public ResponseResult<List<String>> selectAuthorityProjectType() {
        List<String> projectType=authorityManagementService.selectAuthorityProjectType();
        return ResponseResult.success(projectType);
    }

    @GetMapping("/selectAuthorityProjectIbaAttr")
    @ApiOperation(value = "查询项目类型的属性", produces = "application/json; charset=utf-8")
    public ResponseResult< Map<String, Map<String, Set<String>>>> selectAuthorityProjectIbaAttr() {
        Map<String, Map<String, Set<String>>> listMap =authorityManagementService.selectAuthorityProjectIbaAttr();
        return ResponseResult.success(listMap);
    }









}
